# -*- coding:utf-8


from  typing import List

##timeout
class Solution:
    def numOfMinutes(self, n: int, headID: int, manager: List[int], informTime: List[int]) -> int:
        if n == 1:
            return 0

        dataDic = {}

        for pid,managerId in enumerate(manager):
            if managerId in dataDic:
                dataDic[managerId].append(pid)
            else:
                dataDic[managerId] = [pid]


        visited = [0]*n; #有没有被通知到
        maxtime = 0
        q = [(headID,0)]
        while q.__len__()> 0:
            personID,timeSpent = q.pop(0)
            visited[personID] = 1
            maxtime = max(maxtime, informTime[personID] + timeSpent)
            if informTime[personID] != 0:
                for ziId in dataDic[personID]:
                    if informTime[ziId] == 0:
                        continue
                    q.append((ziId,informTime[personID]+timeSpent))
                    # maxtime = max(maxtime,informTime[personID]+timeSpent)

        return maxtime

res = Solution().numOfMinutes(6,
2,
[2,2,-1,2,2,2],
[0,0,1,0,0,0])
print(res)



